<%@page import="javax.persistence.EntityManagerFactory"%>
<%@page import="javax.persistence.TypedQuery"%>
<%@page import="rhserver.MainController"%>
<%@page import="javax.persistence.EntityManager"%>
<%@page import="Entities.Resourcecategory"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Resource Categories</title>
    </head>
    <body>

        <table width="80%" border="1" cellspacing="2" cellpadding="2" align="center">
            <thead>
                <tr>
                    <th>Category Id</th>
                    <th>Category Name</th>
                </tr>
            </thead>
            <tbody>
                
                <%
               List<Resourcecategory> resourceCategories=(List<Resourcecategory>)request.getAttribute("categories");
              for (Resourcecategory category : resourceCategories) {%>
              <tr>
                <td align="center"> <%= category.getId() %> </td> 
                <td align="center"> <%= category.getName()%> </td>
                <td align="center"> <form method="POST" action="ResourceCategoryServlet">
                        <input type="hidden" name="id" value="<%= category.getId() %>">
                        <input type="submit" value="Delete" /></form>
              </tr> 
              <% } %>
            </tbody>
        </table>
        <hr size="5px" />
        <h2>Add a new category:</h2>
        <form method="POST" action="ResourceCategoryServlet">
            Name: <input type="text" name="name" />
            <input type="submit" value="Add" />
        </form>
    </body>
</html>
